package com.gxa.insurance.controller;



import com.gxa.insurance.exception.BusinessException;
import com.gxa.insurance.pojo.DriverComments;
import com.gxa.insurance.service.DriverCommentsService;
import com.gxa.insurance.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.sql.Date;
import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author shen gang
 * @date 2022/6/6
 */
@Api
@RequestMapping("/driverComments")
@RestController
@ResponseBody
@CrossOrigin
public class DriverCommentsController {

    @Autowired
    DriverCommentsService driverCommentsService;
    @ApiOperation(value = "全查询")
    @PostMapping("/selectAll")
    public Map selectAll(){
        List<DriverComments> driverComments = driverCommentsService.selectAll();
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("");
        jsonResult.setData(driverComments);
        return jsonResult.getMap();
    }

    @ApiOperation(value = "根据条件查询的方法",produces = "body")
    @PostMapping("/getEvaluation")
    @ApiImplicitParams({@ApiImplicitParam(name = "name",value = "用户名或手机号或司机名(两个空格二选一)",paramType = "query"),
            @ApiImplicitParam (name = "orderNumber",value = "订单号(两个空格二选一)",paramType = "query")})
    public Map selectLikeName( String name ,String  orderNumber) throws BusinessException {
        List<DriverComments> driverComments1 = driverCommentsService.selectLikeName(name,orderNumber);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(driverComments1);
        return jsonResult.getMap();


    }
    @ApiOperation(value = "查询所用用户,分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "条数",defaultValue = "10",dataType = "int",paramType = "query")
    })
    @PostMapping("/selectByPage")
    public Map selectByPage(@RequestParam("page") Integer page,@RequestParam("size") Integer size) throws Exception {
        Map<String, Object> map = driverCommentsService.selectByPage(page, size);
        Object count = map.get("count");
        Object customers = map.get("customers");
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.put("count",count);
        jsonResult.setData(customers);
        return jsonResult.getMap();
    }
    @ApiOperation(value = "删除的方法")
    @ApiImplicitParam(name = "id" ,value  = "主键编号",paramType = "query")
    @PostMapping("/delete")
    public Map delete(Integer id) throws BusinessException {
        Integer delete = driverCommentsService.delete(id);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        jsonResult.setData(delete);
        return jsonResult.getMap();
    }



    @ApiOperation(value = "通过时间段查询的方法",produces = "body")
    @ApiImplicitParams({@ApiImplicitParam(name = "createTime",value = "起始时间",paramType = "query"),
                            @ApiImplicitParam(name = "overTime",value = "结束时间",paramType = "query"),
                           @ApiImplicitParam(name = "page",value = "页数",paramType = "query"),
                           @ApiImplicitParam(name = "pageSize",value = "条数",paramType = "query"),
    })
    @PostMapping("/selectByTime")
   public Map selectByTime(@RequestBody Map map) throws Exception {
        List<DriverComments> driverComments = driverCommentsService.selectByTime(map);
        int size = driverComments.size();
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.put("count", size);
        jsonResult.setData(driverComments);

        return jsonResult.getMap();
    }
   @ApiOperation(value = "评价详情")
   @ApiImplicitParam(name = "id" ,value = "主键编号",paramType = "query")
   @PostMapping("/selectComments")
   public Map selectComments(Integer id) throws BusinessException {
        DriverComments driverComments = driverCommentsService.selectComments(id);

        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(driverComments);

        return jsonResult.getMap();
    }

}

